/**
 *博尔信基础开发平台
 *<br> 版权声明：厦门博尔信软件有限公司版权所有,违者必究
 *<br> Copyright:  Copyright (c) 2012
 *<br> Company:pearlsoft
 *<br> @author 蒋勇华
 *<br> 2012-5-10
 *<br> @version 1.0
 *————————————————————————————————————
 *修改记录
 *    修改者：
 *    修改时间：
 *    修改原因：
 *——————————————————————————————————————
 */
package com.pearlsoft.webapp.rms.resapply.service;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;

import com.pearlsoft.util.DateUtils;
import com.pearlsoft.webapp.core.dao.RecrodRowMapper;
import com.pearlsoft.webapp.core.dataset.Record;
import com.pearlsoft.webapp.core.dataset.SimpleRecord;

/**
 *描述： 
 *
 * 
 */
public class ResApplyRowMapperHelper {
	public static RecrodRowMapper<Record> generalRowMapper(){
		return new  RecrodRowMapper<Record>(){
			@Override
			public Record mapRow(ResultSet rs, int rowNum)
					throws SQLException {
				SimpleRecord recrod = new SimpleRecord();
				recrod.setValue("stepId", rs.getString(1));
				recrod.setValue("flowId", rs.getString(2));
				recrod.setValue("authorId", rs.getString(3));
				recrod.setValue("stepName", rs.getString(4));
				recrod.setValue("stepType",rs.getInt(5));
				
				recrod.setValue("startTime", rs.getDate(6)==null ?"":DateUtils.getTimeStr(new Date(rs.getTimestamp(6).getTime())));
				recrod.setValue("endTime", rs.getDate(7)==null ?"":DateUtils.getTimeStr(new Date(rs.getTimestamp(7).getTime())));
				recrod.setValue("opinion", rs.getString(8));
				recrod.setValue("stepstatus", rs.getString(9));
				recrod.setValue("applyId", rs.getString(10));
				recrod.setValue("resName", rs.getString(11));
				recrod.setValue("resDesc", rs.getString(12));
				recrod.setValue("startDate", rs.getDate(13)==null ?"":DateUtils.getDateFormat(new Date(rs.getDate(13).getTime()),"yyyy-MM-dd"));
				recrod.setValue("endDate", rs.getDate(14)==null ?"":DateUtils.getDateFormat(new Date(rs.getDate(14).getTime()),"yyyy-MM-dd"));
				
				

				return recrod;
			}
		};
	}
	public static RecrodRowMapper<Record> resApplyRowMapper(){
		return new  RecrodRowMapper<Record>(){
			@Override
			public Record mapRow(ResultSet rs, int rowNum)
					throws SQLException {	
				SimpleRecord recrod = new SimpleRecord();
				recrod.setValue("applyId", rs.getString(1));
				recrod.setValue("resName", rs.getString(2));
				recrod.setValue("resDesc", rs.getString(3));
			
				recrod.setValue("startDate", rs.getDate(4)==null ?"":DateUtils.getDateFormat(new Date(rs.getDate(4).getTime()),"yyyy-MM-dd"));
				recrod.setValue("endDate", rs.getDate(5)==null ?"":DateUtils.getDateFormat(new Date(rs.getDate(5).getTime()),"yyyy-MM-dd"));
				recrod.setValue("authorId",rs.getString(6));
				recrod.setValue("user_name",rs.getString(7));
				recrod.setValue("endTime", rs.getDate(8)==null ?"":DateUtils.getTimeStr(new Date(rs.getTimestamp(8).getTime())));
				recrod.setValue("eName", rs.getString(9));
				
				return recrod;
			}
		};
	}
	public static RecrodRowMapper<Record> hostConfigRowMapper(){
		return new  RecrodRowMapper<Record>(){
			@Override
			public Record mapRow(ResultSet rs, int rowNum)
					throws SQLException {
				String fields="configId,applyId,hostName,vmName,hostDesc,opsSeries,";
				fields = fields +"opsName,vVersion,cups,memory,memoryunit,storage,";
				fields = fields +"storageunit,netcards,zxtype,hostIp";
				SimpleRecord recrod = new SimpleRecord();
				String[] fieldsArr = fields.split(",");
				for(int i=0;i<fieldsArr.length;i++ ){
					recrod.setValue(fieldsArr[i], rs.getString(i+1));
				}
				return recrod;
			}
		};
	}	
	/***
	 * 审批日志
	 * @return
	 */
	public static RecrodRowMapper<Record> auditLogRowMapper(){
		return new  RecrodRowMapper<Record>(){
			@Override
			public Record mapRow(ResultSet rs, int rowNum)
					throws SQLException {
				SimpleRecord recrod = new SimpleRecord();
				recrod.setValue("stepName", rs.getString(1));
				recrod.setValue("user_name", rs.getString(2));
				recrod.setValue("endTime", rs.getDate(3)==null ?"":DateUtils.getTimeStr(new Date(rs.getTimestamp(3).getTime())));
				recrod.setValue("opinion", rs.getString(4));
				recrod.setValue("result",rs.getString(5));				
				return recrod;
			}
		};
	}
	
}
